using Perfect.Marshal;
using System.Xml;

namespace editor
{
namespace cfg.obj
{
[System.Serializable]
public  class GameObjectData : GameObjectInstance
 {

    public cfg.obj.GameObject gameObject  = new cfg.obj.GameObject();
     


    public const int TYPE_ID = 1729738532;

    public override int GetTypeId() {
        return TYPE_ID;
    }


    public override void MarshalCompatible(Perfect.Marshal.Octets os) {
        os.WriteSize(8);
        os.WriteSize(Tag.INT | (1 << Tag.TAG_SHIFT));  os.WriteInt(instanceId);  
         os.WriteSize(Tag.STRING | (2 << Tag.TAG_SHIFT));  os.WriteString(name);  
         os.WriteSize(Tag.STRING | (3 << Tag.TAG_SHIFT));  os.WriteString(tag);  
         os.WriteSize(Tag.BOOL | (4 << Tag.TAG_SHIFT));  os.WriteBool(active);  
         os.WriteSize(Tag.BEAN | (5 << Tag.TAG_SHIFT));  { var _oldOs = os; os = new Perfect.Marshal.Octets(); cfg.Extensions.marshal_compatible_cfg_obj_Transform(transform,os);  _oldOs.WriteOctets(os); os = _oldOs;}  
         os.WriteSize(Tag.LIST | (6 << Tag.TAG_SHIFT));  { var _oldOs = os; os = new Perfect.Marshal.Octets(); cfg.Extensions.marshal_compatible_list_cfg_obj_GameObjectParam(objectParams,os);  _oldOs.WriteOctets(os); os = _oldOs;}  
         os.WriteSize(Tag.BOOL | (7 << Tag.TAG_SHIFT));  os.WriteBool(isPhase);  
         os.WriteSize(Tag.BEAN | (21 << Tag.TAG_SHIFT));  { var _oldOs = os; os = new Perfect.Marshal.Octets(); cfg.Extensions.marshal_compatible_cfg_obj_GameObject(gameObject,os);  _oldOs.WriteOctets(os); os = _oldOs;}  
         
    }

    public override void UnmarshalCompatible(Perfect.Marshal.Octets os) {
        for (int _var_num_ = os.ReadSize(); _var_num_-- > 0; ) {
            int _id_ = os.ReadSize();
            switch (_id_)
            {
            case (Tag.INT | (1 << Tag.TAG_SHIFT)):   instanceId = os.ReadInt(); break;  
             case (Tag.STRING | (2 << Tag.TAG_SHIFT)):   name = os.ReadString(); break;  
             case (Tag.STRING | (3 << Tag.TAG_SHIFT)):   tag = os.ReadString(); break;  
             case (Tag.BOOL | (4 << Tag.TAG_SHIFT)):   active = os.ReadBool(); break;  
             case (Tag.BEAN | (5 << Tag.TAG_SHIFT)):  { var _oldOs = os; os = os.ReadOctets(); transform = cfg.Extensions.unmarshal_compatible_cfg_obj_Transform(os); os = _oldOs; break; }   
             case (Tag.LIST | (6 << Tag.TAG_SHIFT)):  { var _oldOs = os; os = os.ReadOctets(); objectParams = cfg.Extensions.unmarshal_compatible_list_cfg_obj_GameObjectParam(os); os = _oldOs; break; }   
             case (Tag.BOOL | (7 << Tag.TAG_SHIFT)):   isPhase = os.ReadBool(); break;  
             case (Tag.BEAN | (21 << Tag.TAG_SHIFT)):  { var _oldOs = os; os = os.ReadOctets(); gameObject = cfg.Extensions.unmarshal_compatible_cfg_obj_GameObject(os); os = _oldOs; break; }   
             
            default: Tag.SkipUnknownField(_id_, os); break;
            }
         }
    }
    public override void MarshalXml(XmlWriter ele)
    {
        ele.WriteAttributeString("type", "GameObjectData");
        ele.WriteStartElement("instanceId"); ele.WriteAttributeString("id", "1"); ele.WriteInt(instanceId); ele.WriteEndElement();
         ele.WriteStartElement("name"); ele.WriteAttributeString("id", "2"); ele.WriteString2(name); ele.WriteEndElement();
         ele.WriteStartElement("tag"); ele.WriteAttributeString("id", "3"); ele.WriteString2(tag); ele.WriteEndElement();
         ele.WriteStartElement("active"); ele.WriteAttributeString("id", "4"); ele.WriteBool(active); ele.WriteEndElement();
         ele.WriteStartElement("transform"); ele.WriteAttributeString("id", "5"); cfg.Extensions.xml_marshal_cfg_obj_Transform(transform,ele); ele.WriteEndElement();
         ele.WriteStartElement("objectParams"); ele.WriteAttributeString("id", "6"); cfg.Extensions.xml_marshal_list_cfg_obj_GameObjectParam(objectParams,ele); ele.WriteEndElement();
         ele.WriteStartElement("isPhase"); ele.WriteAttributeString("id", "7"); ele.WriteBool(isPhase); ele.WriteEndElement();
         ele.WriteStartElement("gameObject"); ele.WriteAttributeString("id", "21"); cfg.Extensions.xml_marshal_cfg_obj_GameObject(gameObject,ele); ele.WriteEndElement();
         
    }

    public override void UnmarshalXml(XmlElement ele)
    {
        foreach (XmlElement e in ele.GetChildren())
        {
            if (int.TryParse(ele.GetAttribute("id"), out var _id_))
            {
                switch (_id_)
                {
                case 1:  instanceId = ele.ReadInt(); break; 
                 case 2:  name = ele.ReadString2(); break; 
                 case 3:  tag = ele.ReadString2(); break; 
                 case 4:  active = ele.ReadBool(); break; 
                 case 5:  transform = cfg.Extensions.xml_unmarshal_cfg_obj_Transform(ele); break; 
                 case 6:  objectParams = cfg.Extensions.xml_unmarshal_list_cfg_obj_GameObjectParam(ele); break; 
                 case 7:  isPhase = ele.ReadBool(); break; 
                 case 21:  gameObject = cfg.Extensions.xml_unmarshal_cfg_obj_GameObject(ele); break; 
                 
                default: break;
                }
            }
            else
            {
                switch (e.Name)
                {
                case "instance_id":  instanceId = ele.ReadInt(); break; 
                 case "name":  name = ele.ReadString2(); break; 
                 case "tag":  tag = ele.ReadString2(); break; 
                 case "active":  active = ele.ReadBool(); break; 
                 case "transform":  transform = cfg.Extensions.xml_unmarshal_cfg_obj_Transform(ele); break; 
                 case "object_params":  objectParams = cfg.Extensions.xml_unmarshal_list_cfg_obj_GameObjectParam(ele); break; 
                 case "is_phase":  isPhase = ele.ReadBool(); break; 
                 case "game_object":  gameObject = cfg.Extensions.xml_unmarshal_cfg_obj_GameObject(ele); break; 
                 
                default: break;
                }
            }
        }
    }
}
}
}
